﻿@model instamuz.Application.ViewModels.AccountFeedViewModel

@{
    ViewBag.Title = "Account feed";
}

<h1>@Model.AccountName feed</h1>

@if (Model.AlreadyFollow == false)
{
    <div class="alert alert-info">
        <button id="follow-account" data-account-id="@Model.AccountId" class="btn btn-primary">Подписаться</button>
    </div>
}

@if (Model.CanPost)
{
    <div class="alert alert-info">
        @using (Html.BeginForm("post", "index", FormMethod.Post, new {@class = "form-horizontal", id = "post-form"}))
        {
            <textarea id="post-description" class="input-xxlarge" rows="2"></textarea>
        }
        <button id="post-new" class="btn btn-primary" type="submit">Запостить</button>
    </div>
}

@foreach (var post in Model.Posts)
{
    <div class="alert alert-info">
        <strong>Музыкальный пост</strong>
        @post.Description
    </div>
}

<script type="text/javascript">

    $('#follow-account').click(function () {
        var accountId = $(this).data('account-id');

        var params =
            {
                url: '@Url.Action("follow", "account")',
                type: 'POST',
                dataType: 'html',
                data: {
                    id: accountId
                },
                complete: function (j, s) {
                    alert('OK');
                }
            };

        $.ajax(params);
    });

    $('#post-new').click(function () {
        var desc = $('#post-form > #post-description').val();

        var params =
            {
                url: '@Url.Action("post", "account")',
                type: 'POST',
                dataType: 'html',
                data: {
                    description: desc
                },
                complete: function (j, s) {
                    alert('OK, refresh');
                }
            };

        $.ajax(params);
    });
</script>